<template>
<div class="friend">
  <NavBar></NavBar>
  <div class="main">
  <!-- 容器 -->
  <el-row :gutter="0" type="flex" justify="center" class="container" >
    <!-- 动态 -->
  <el-col class="condition">
    <!-- 动态内容 -->
    <el-card class="box-card">
      <!-- 头部 -->
      <div slot="header" class="clearfix ">
          <span class="title">动态</span>
           <el-button @click="addBtn" style="float: right; padding: 5px 10px;" round>
             <i class="el-icon-edit"></i>
             发布动态
             </el-button>
          <span style="float: right;"  >&nbsp;&nbsp;&nbsp;</span>
            <el-button style="float: right; padding: 5px 10px;"  round>
             <i class="wyy wyy-fabushipin"></i>
              发布视频
              </el-button>
      </div>
      <!-- 发表内容 -->
       <div v-for="item in list" :key="item.id" class="text item">
          <el-row type="flex" justify="start" class="box_content" >
            <!-- 头像 -->
            <el-col class="img">
               <img :src="item.user.avatarUrl" alt="">
            </el-col>
            <el-col class="dynamic_content">
              <div class="dynamic_content_name">
              <a href="#">{{ item.user.nickname }}</a>
              <i  class="el-icon-share"></i>
              <span>{{ item.type }}</span>
              </div>
               <div class="dynamic_content_time">
                {{item.showTime | relativeTime}}
               </div>
               <div class="dynamic_content_text">
                 {{ item.arr.msg }}
                 <!-- <a href="#">#把评论唱成歌#</a>
                超级温柔的古风音乐人
                <a href="#">@沈谧仁mile</a>
                 邀你来互动啦~快来他的评论区找他玩吧～你的留言很可能被他编成歌词写进歌里哦！[多多耍酷] -->
               </div>
              <div class="music" @click="$router.push(`/song/${ (item.arr.song ||item.arr.playlist).id }`)">
                <div class="music_l">
                  <img :src="item|changeImg" alt="">
                </div>
                <div class="music_r">
                  <h4 class="music_name">{{  (item.arr.song ||  item.arr.playlist).name  }}</h4>
                  <h4 class="author_name">{{ item | conStr }}</h4>
                </div>
              </div>
              <div class="pic">
                <img :src="v.originUrl" v-for="(v,i) in item.pics" :key="i" alt="">
              </div>
              <div class="doper">
                  <a href="javascript:;" @click="like(item.id,item.type)">
                    <i class="el-icon-s-opportunity"></i>(5)
                  </a>
                  <span class="line">|</span>
                  <a href="javascript:;">转发(5)</a>
                  <span class="line">|</span>
                  <a href="javascript:;">评论(16)</a>

              </div>
      </el-col>

    </el-row>

       </div>
  </el-card>
</el-col>
  <!-- 个人 -->
  <el-col  class="information">
      <div class="userinfo_b">
        <a href="javascript:;" class="face">
          <img src="../../assets/01.jpg" alt="">
        </a>
        <h5 class="f-thide">{{ this.user.profile.nickname }}</h5>
        <p class="f-brk">{{ this.user.profile.signature }}</p>
        <ul class="f-cb">
          <li>
            <a href="javascript:;">
              <em>{{this.user.profile.eventCount}}</em>
              <i>动态</i>
            </a>
          </li>
            <li>
            <a href="javascript:;">
               <em>{{this.user.profile.follows}}</em>
              <i>关注</i>
            </a>
          </li>
            <li>
            <a href="javascript:;">
               <em>{{this.user.profile.followeds}}</em>
               <i>粉丝</i>
            </a>
          </li>

        </ul>
      </div>
      <div class="star_r">
          <div class="star_hd">
              <h4>明星用户</h4>
              <a href="javascript:;" @click="toggle">换一换</a>
          </div>

              <ul class="star_bd_li">
                <li v-for="(v,i) in hotArtists" :key="i">
                  <img :src="v.img1v1Url" alt="">
                  <div class="star_bd_a">
                    <span class="star_name">{{ v.name }}</span>
                   <span class="star_info">歌手{{ v.name }}   代表作《你快回来》《燃烧》</span>
                  </div>
                  <el-button size="small" round @click="focus(v.id)">关注</el-button>
                </li>
              </ul>

      </div>
  </el-col>
</el-row>
  <div class="footer">

  </div>
  </div>
  <FaBu :isShow.sync = isShow @reset ="dynamic"></FaBu>
     <el-backtop targer="document.body"></el-backtop>
</div>
</template>

<script>
import NavBar from '@/components/NavBar/index'
import { dynamic, hotArtists, follow, userFollows, like } from '@/api/index'
import FaBu from './components/fabu.vue'
export default {
  name: 'Friend',
  components: {
    NavBar,
    FaBu
  },
  data () {
    return {
      list: [],
      user: this.$store.state.user,
      hotArtists: [],
      isShow: false,
      t: 0
    }
  },
  created () {
    this.dynamic()
    this.hotArtist()
    // this.zzz()
  },
  methods: {

    async like (id, type) {
      this.t = this.t ? 0 : 1
      const res = await like({
        t: this.t,
        id,
        type
      })
      console.log(res)
    },
    addBtn () {
      this.isShow = true
    },
    async dynamic () {
      try {
        const { data } = await dynamic(30)
        console.log(data)
        this.list = data.event
        this.list.forEach(item => {
          item.arr = JSON.parse(item.json)
          // console.log(item.arr.album.blurPicUrl)
        })
        this.list = this.list.filter(v => v.arr.song || v.arr.playlist)
      } catch (error) {
        console.log(error, 'hehe')
      }
    },
    async hotArtist () {
      try {
        const { data } = await hotArtists()

        this.hotArtists = data.artists
        const arr = []
        for (let i = 0; i < 5; i++) {
          arr.push(Math.floor(Math.random() * 50))
        }
        this.hotArtists = this.hotArtists.filter((v, i) => arr.includes(i))
      } catch (err) {
        this.$message('请求热门歌手出错')
      }
    },
    toggle () {
      this.hotArtist()
    },
    async focus (id) {
      const { data: { follw } } = await userFollows(this.user.account.id)
      console.log(follw)
      console.log(id)
      const res = await follow({ id: `18${id}`, t: 1 })
      console.log(res)
    }

  },
  filters: {
    // 拼接名字
    conStr: function (data) {
      if (data.arr.song) {
        const arr = []
        data.arr.song.artists.forEach(v => {
          if (v.name) {
            arr[arr.length] = v.name
          }
        })
        const str = arr.join('/')
        return str
      } else {
        return `by ${data.user.nickname}`
      }
    },
    // 选图
    changeImg: function (data) {
      if (data.arr.song) {
        return data.arr.song.img80x80
      } else {
        return data.arr.playlist.coverImgUrl
      }
    }

  }
}
</script>

<style lang="less" scoped>
.friend {
  .main {
    width: 980px;
    margin: 0 auto;
  }
  .container{

  a{
    color: #0c73c2;
  }
  .box_content{
      padding-bottom: 20px;
      border-bottom: 1px solid #ccc;
  }
   .condition{
    width: 680px;
    background-color: #fff;
    border-left: 1px solid red;
    border-right: 1px solid red;
  .text {
    font-size: 14px;
     .img{
         width: 54px;
         height: 45px;
         margin-right: 10px;
        /* background-color: pink; */
      img{
        width: 45px;
        height: 45px;
      }
       }
      .dynamic_content{
      margin-top: 3px;

        i {
          margin: 0 5px;
       }
       .dynamic_content_time{
         margin-top: 7px;
         color: #999;
         font-size: 14px;
       }
       .dynamic_content_text{
         margin-top: 10px;

       }
       .music{
         display: flex;
         align-items:center;
         background-color: #f5f5f5;
         height: 60px;
         margin-top: 15px;
        h4{
          font-weight: 400;
        }
        img{
           width: 40px;
           height: 40px;
           margin-left: 10px;
           /* background-color: pink; */
        }
       .music_r{
           display: flex;
           flex-direction: column;
           justify-content:space-between;
           align-items:flex-start;
           line-height: 22px;
           margin-left: 8px;
           .music_name{
             margin-top: -2px;
             color: #333;

           }
           .author_name{
             font-size: 12px;
             color: #666;
           }
        }
       }
       .pic{
         width: 330px;
         margin-top: 15px;
         img{
           width: 100px;
           height: 100px;
           margin: 5px;
         }
       }
       .doper{
        margin: 18px 0 -2px;
        text-align: right;
        line-height: normal;
        font-size: 12px;
        .line{
            color: #c7c7c7;
             margin: 0 10px 0 12px;
        }
       }
      }
   }
  .el-card{
    color: #666;
  }
   /deep/.el-card__body{
    padding: 20px 0;
  }
  /deep/ .el-card__header{
    padding: 18px 5px 5px 5px;
    border-bottom: 2px solid red;
    box-sizing: border-box;
  }
  .title{
    font-size: 24px;
    font-weight: 400;
    font-size: #333;
  }

  .item {
    margin-bottom: 18px;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }
  .clearfix:after {
    clear: both
  }

  .box-card {
    width: 100%;
    padding: 0 30px;
    .clearfix{
       i {
      color: red;
      font-size: 16px;
      }
    }

    }
  }
   .information{
     width: 300px;
     background-color: #f2f2f2;
     border-right: 1px solid red;
    .userinfo_b{
      position: relative;
      height: 193px;
      background-color: #FFF;
      /* background: url('../../assets/01.jpg') no-repeat; */
      /* background-size: 172px; */
      .face{
        position: absolute;
        top: 38px;
        left: 30px;
        width: 70px;
        height: 70px;

        display: flex;
        justify-content: center;
        align-items: center;
        background-color: #fff;
        border: 1px solid #ccc;
        img {
          width: 65px;
        }
      }
      .f-thide{
        position: absolute;
        left: 112px;
        top: 40px;
        font-size: 14px;
        width: 180px;
        overflow: hidden;
       text-overflow: ellipsis;
        white-space: nowrap;
        word-wrap: normal;
      }
      .f-brk{
        position: absolute;
        left: 112px;
        width: 160px;
        top: 67px;
        height: 38px;
        overflow: hidden;
       line-height: 19px;
        color: #888;
      }
      .f-cb{
        position: absolute;
        top: 134px;
        left: 13px;
        overflow: hidden;
        li {
          display: inline;
          float: left;
          list-style: none;
          margin: 0 2px 0 -2px;
          border-left: 1px solid #c2c2c2;
          a{
            display: block;
            padding: 0 20px;
            line-height: 24px;
            color: #666;
            display: flex;
            flex-direction: column;
            justify-content:space-between;
          }
        }
      }
    }
    .star_r{
      padding: 20px;
      .star_hd{
        display: flex;
        justify-content:space-between;
        line-height: 30px;
        border-bottom: 1px solid red;
        h4{
          font-size: 12px;
        }
        a{
          font-size: 12px;
          color: #666;
        }
      }

      ul{
        display: block;
        list-style-type: disc;
        li {
          display: flex;
          justify-content:space-between;
          align-items: center;
          list-style:none;
          height:45px ;
          margin-top: 20px;
          padding-right: 20px;
          img {
            width: 45px;
             height: 45px;
          }

        }
        .star_bd_a{
          width: 100px;
          height: 45px;
          display: flex;
          flex-direction: column;
          justify-content:space-around;
          font-size: 12px;
          .star_info{
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
             word-wrap: normal;
             color: #9b9b9b;
          }
        }
      }

    }
  }
}
.footer{
  height: 172px;
  border-top: 1px solid red;
}
}
</style>
